<template>
  <div>
    <el-form ref="detailForm" :model="detail" label-width="80px" size="small">
      <el-form-item prop="name" label="名称">
        <el-input v-model="detail.name"></el-input>
      </el-form-item>
      <el-form-item prop="sort" label="序号" v-if="false">
        <el-input v-model="detail.sort"></el-input>
      </el-form-item>
      <el-form-item prop="status" label="状态" v-if="false">
        <el-input v-model="detail.status"></el-input>
      </el-form-item>
      <el-row :gutter="20">
        <el-col :span="24">
          <d2-ueditor v-model="detail.detailUrl"/>
        </el-col>
        <!-- <el-col :span="10">
                    <el-card v-if="text" shadow="never" style="border: 1px solid #d4d4d4;">
                        <template slot="header">Result</template>
                        <div v-html="text" style="margin: -20px 0px;"></div>
                    </el-card>
        </el-col>-->
      </el-row>
      <el-form-item>
        <el-button type="primary" :loading="loading" @click="saveUser">保存</el-button>
        <el-button @click="closeWindow">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import docApi from "@/api/system/doc";
  import {mapActions} from "vuex";

  export default {
    name: "docAddForm",
    data() {
      return {
        loading: false,
        dialogVisible: false,
        detail: {}
      };
    },
    watch: {
      value(val) {
        this.dialogVisible = val;
      },
      dialogVisible(val) {
        this.$emit("input", val);
      }
    },
    async mounted() {
      this.detail = {};
      this.detail.id = this.$route.params.id;
      if (this.detail.id) {
        let res = await docApi.info({id: this.detail.id})
        this.detail = res.data
      }
    },
    methods: {
      ...mapActions("d2admin/page", ["close"]),
      async dialogOpen() {
      },
      saveUser() {
        this.$refs["detailForm"].validate(async valid => {
          if (!valid) {
            return
          }
          this.loading = true;
          let method = this.detail.id ? docApi.mod : docApi.add;
          await method(this.detail);
          this.loading = false;
          this.closeWindow();
          this.$emit("submit");
        });
      },
      closeWindow() {
        this.close({tagName: "/doc/detail"});
      },
    }
  };
</script>

